{-# OPTIONS -Wall #-}

module Demo02 where


import Majalan.Base

import Majalan.Pitch.ET12
import Majalan.Symbolic.SimpleNoteList




data Orch = WG_BOWED_BAR | ZAKOUT
  deriving (Eq,Ord,Show)

instance CsOrch Orch where
  instNumber WG_BOWED_BAR = 1
  instNumber ZAKOUT       = 2



wgBowedBar :: Decimal -> Decimal -> Decimal -> Event uctx ()
wgBowedBar iamp ipch iconst = 
    let izakout = 1 in
    makeEvent WG_BOWED_BAR () (const [ VFloat iamp
                                     , VFloat ipch
                                     , VFloat iconst
                                     , VInt   izakout
                                     ])
                              


zakout :: Processor
zakout = 
    let izakin = 1 in makeProcessor ZAKOUT 2.0 [ VInt izakin ]


genBowedBar :: GenEvent uctx ()
genBowedBar = \pch amp -> wgBowedBar amp pch 0

-- | Pitch in csound manual example is c3 (7.00) (130.813 Hz)
notes :: Phrase
notes = phrase $ [ c_3, d_3, c_3 ]


--
-- WARNING 
-- =======
-- wgbowedbar seems very sensitive to kamp(litude)
-- (first input param).
-- 
-- To get a range of amplitudes you would have to post-process
-- (scale) the signal. Remember though that many physical 
-- instruments are extremely limited in their amplitude range 
-- Expecting instruments to go from ppp to fff is unrealistic.
--

type MyCtx = ()

ctx_zero :: MyCtx
ctx_zero = ()


score01 :: ScoreObj
score01 = score default_timeline ctx_zero $ do 
    sys1 <- part $ eventList 0 $ evalAdvance 0 $ unphrase genBowedBar notes
    bracket sys1 zakout 



col_specs :: ColumnSpecs
col_specs = columnSpecs [ (WG_BOWED_BAR, cols_bowed_bar) 
                        , (ZAKOUT,       cols_zakout)
                        ]
  where             
    cols_bowed_bar  = [ defaultFormat "amp", defaultFormat "pch"
                      , defaultFormat "const", defaultFormat "zout" ]
    cols_zakout     = [ defaultFormat "zakin" ]






demo01 :: IO ()
demo01 = shellTest odac "orc/wgbowedbar.orc" $ renderScoreObj col_specs score01

